package com.example.sqlitetest.Adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
import com.example.sqlitetest.R;
import com.example.sqlitetest.db.MyDataBaseHelper;
import com.example.sqlitetest.model.LiuYanNumInfo;



import java.util.List;

public class LiuYanNumAdapter extends BaseAdapter {
    //定义数据
    private List<LiuYanNumInfo> mData;
    //定义Inflater,加载我们自定义的布局
    private LayoutInflater mInflater;
    //定义上下文
    private Context con;

    private MyDataBaseHelper mHelper;

    //定义构造器
    public LiuYanNumAdapter(Context context, LayoutInflater inflater, List<LiuYanNumInfo> data) {
        con = context;
        mInflater = inflater;
        mData = data;
    }


    @Override
    public int getCount() {
        return mData.size();
    }

    @Override
    public Object getItem(int position) {
        return position;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }


    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        View viewLiuyan = mInflater.inflate(R.layout.list_item_6,null);
        LiuYanNumInfo liuyan = mData.get(position);

        //获得自定义布局中每一个控件的对象
        final TextView num = (TextView)viewLiuyan.findViewById(R.id.num);
        final TextView name = (TextView)viewLiuyan.findViewById(R.id.name);

        mHelper = new MyDataBaseHelper(con);


        //将数据添加到自定义的布局中去
        name.setText(liuyan.getName());
        num.setText(liuyan.getNum());


        return viewLiuyan;
    }
}
